<html>
<head>
	<title>GMNotifier Gmail New Email Notification Apps</title>
<script type="text/javascript" src="jquery-1.8.1.min.js"></script>
<script type="text/javascript" src="jquery.jfeed.js"></script>
<script>
$(document).ready(function(){
localStorage.setItem('playsoundnotification',1);
localStorage.setItem('closenotificationafter',10000);
var oAudio = document.getElementById('myaudio');
oAudio.src="sounds/email_message.mp3";
checkNewPosts();
var timer=setInterval(function(){
checkNewPosts();
},30000);

function checkNewPosts(){
	$.getFeed({
        url: 'https://mail.google.com/mail/feed/atom/unread',
        success: function(feed) { 
            for(var i = 0; i < feed.items.length && i < 5; i++) {            
                var item = feed.items[i];
                var title=item.title;
                var description=item.description;
                localStorage.setItem('title',title);
                localStorage.setItem('description',description);
                	sendNotification(title,description);
                }

                if(feed.items.length>0){
                     var playsound=parseInt(localStorage.getItem('playsoundnotification'));
                     if(playsound){                        
                        oAudio.play();
                     }
                }

        }    
    });
}

});
function sendNotification(title,msg,link) {
		var notification = webkitNotifications.createNotification('images/icon-48x48.png',title,msg);
		notification.show();
        var closenotificationafter=parseInt(localStorage.getItem('closenotificationafter'));
        
		setTimeout(function(){
			notification.cancel();
		},closenotificationafter);
}    
	</script>
	</head>
	<body>
    <audio id="myaudio">
      HTML5 audio not supported
    </audio>
	</body>
	</html>